<?php
/*
 * @Author: lokei
 * @Date: 2022-11-15 12:29:54
 * @LastEditors: lokei
 * @LastEditTime: 2022-11-15 12:38:34
 * @Description: 
 */
namespace App\Http\Controllers\Cms\Article;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Cms\Article\ArticleRecommendModel;
use Illuminate\Http\Request;

class RecommendController extends Controller {
    public function get(Request $request) {
        $res = ResultTool::success();
        $recommend = ArticleRecommendModel::where('scene', '=', $request->input('scene'))->first();
        if(is_null($recommend)) {
            $recommend = new ArticleRecommendModel();
            $recommend->scene = $request->input('scene');
            $recommend->save();
            $res['data']['articles'] = '';
        } else {
            $res['data']['articles'] = $recommend->article_list;
        }
        return $res;
    }

    public function set(Request $request) {
        $recommend = ArticleRecommendModel::where('scene', '=', $request->input('scene'))->first();
        if(is_null($recommend)) {
            $recommend = new ArticleRecommendModel();
            $recommend->scene = $request->input('scene');
            $recommend->article_list = $request->input('articles');
            $recommend->save();
            $res['data']['articles'] = '';
        } else {
            $recommend->article_list = $request->input('articles');
            $recommend->save();
        }
        return ResultTool::success();
    }
}